#!/bin/bash
# file : /pwd/shell/gitpull.sh

# 修改地址
cd `pwd`
# 修改日志地址
gitlog='/pwd/git.log'

today=`date +%Y%m%d`
gitstatus=`git status`
echo '检测库状态'
if [[ $gitstatus == *"working directory clean"* ]];then 
	echo '无任何改变'
	echo '拉取'
	git pull >> $gitlog
else 
	echo '有文件变动'
	echo '将改变提交到分支 '$today
	git checkout -b $today 

	echo '写入日志'
	touch $gitlog
	echo " " >> $gitlog 
	date '+%Y-%m-%d %H:%M' >> $gitlog
	echo "==========================================" >> $gitlog
	git diff >> $gitlog
	echo "==========================================" >> $gitlog
	echo " " >> $gitlog 

	git add .
	git commit -a -m 'its change'
	echo '回到 master'
	git checkout master
	echo '删除分支'
	git branch -D $today
	echo '拉取'
	git pull >> $gitlog
fi

